<template>
    <rui-page :defines="defines">
        <rui-query :label-width="200"
                   ref="searchForm"
                   :query="queryData"
                   :query-rows="searchFormOptions"
        />
        <rui-table
            :defineId="'voucherFlowDefine'"
            :fixedLeft="['action']"
            :showIndex="false"
            :select="false"
            :columns="status=='failCreated'?infoColumns:columns"
            :slots="[{key:'action',slot:'action'}]"
            @loadDatas="queryData"
            ref-query="searchForm"
            ref="infoTable"
        >
            <template slot="action" slot-scope="{ row }">
                <div>
                    <Button @click="resetFlowStatus(row)" size="small" type="warning" v-if="row.status=='failCreated'">重置凭证流水状态
                    </Button>
                    <circleLoading v-if="operationLoading"/>
                </div>
            </template>
        </rui-table>
    </rui-page>
</template>
<script>
    import voucherFlowDefine from "../defines/voucher-flow-define";
    import circleLoading from "_c/circle-loading/circle-loading.vue";
    import {
        getVoucherFlowList,
        resetFlowStatus,
        resetItemStatus
    } from "@/projects/basic/api/contract/voucher/voucherFlow";

    export default {
        name: "voucherFlowInfo",
        props: {
            status: {
              type: String,
            }
        },
        components: {
            circleLoading
        }
        ,
        data() {
            return {
                operationLoading: false,
                submitLoading: false,
                searchFormOptions: [
                    {
                        defineId: "voucherFlowDefine",
                        span: 6,
                        fields: ["contractNo", "buriedPointNo"]
                    }
                ],

                infoColumns: [
                    'action', 'status', 'transNo', 'buriedPointNo', 'contractNo',"keepAccountDate","errMsg"],
                columns: [
                      'status', 'transNo', 'buriedPointNo', 'contractNo',"keepAccountDate","errMsg"],
            };
        }
        ,
        computed: {
            defines() {
                return [
                    {
                        id: "voucherFlowDefine",
                        fields: voucherFlowDefine
                    }
                ];
            }
        }
        ,
        methods: {
            queryData(queryData) {
                console.log(queryData);
                queryData.condition.status =this.status;
                this.operationLoading=true;
                getVoucherFlowList(queryData).then(res => {
                        if (res.code === "0000") {
                            let {records, total} = res.data;
                            this.$refs.infoTable.updateTableData(records, total);
                            this.operationLoading=false;
                        }
                    }).catch(() => {
                    this.operationLoading = false;
                });
            },
            refresh() {
                this.$refs['infoTable'].reloadData();
            },
            //红冲
            resetFlowStatus(v) {
                this.$Modal.confirm({
                    title: "重置凭证流水状态",
                    content: "您确认要重置凭证流水状态?",
                    onOk: () => {
                        this.operationLoading = true;
                        resetFlowStatus(v.id).then(res => {
                            this.operationLoading = false;
                            if (res.code === "0000") {
                                this.$Message.success("重置凭证流水状态成功");
                                this.refresh();
                            }
                        }).catch(() => {
                            this.operationLoading = false;
                        });
                    }
                });
            }
            ,
            //重新发送
            resetItemStatus(v) {
                this.$Modal.confirm({
                    title: "重置辅助帐发送状态",
                    content: "您确认要重置辅助帐发送状态?",
                    onOk: () => {
                        this.operationLoading = true;
                        resetItemStatus(v.id).then(res => {
                            this.operationLoading = false;
                            if (res.code === "0000") {
                                this.$Message.success("重置辅助帐发送状态成功");
                                this.refresh();
                            }
                        }).catch(() => {
                            this.operationLoading = false;
                        });
                    }
                });
            } ,
        } ,
        mounted() {
            this.refresh();
        }
    }
    ;
</script>
